| Total Complexity | 4 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | export default class SmileyConf { |
||
| 2 | static getSmileys() { |
||
| 3 | return JSINFO.SMILEY_CONF; |
||
|
|
|||
| 4 | } |
||
| 5 | |||
| 6 | /** |
||
| 7 | * Regex escape as recommended by MDN |
||
| 8 | * |
||
| 9 | * @param {string} string |
||
| 10 | * @returns {string} |
||
| 11 | */ |
||
| 12 | static escapeRegExp(string) { |
||
| 13 | return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string |
||
| 14 | } |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Build Regex from conf |
||
| 18 | * |
||
| 19 | * Similar to DokuWiki parser but without lookbehind (currently supported only by Chrome) |
||
| 20 | * @see \Doku_Parser_Mode_smiley |
||
| 21 | * |
||
| 22 | * @returns {RegExp} |
||
| 23 | */ |
||
| 24 | static getRegex() { |
||
| 25 | const smileyGroups = Object.keys(this.getSmileys()) |
||
| 26 | .map(smiley => SmileyConf.escapeRegExp(smiley)); |
||
| 27 | return new RegExp(`(?:\\W|^)(${smileyGroups.join('|')})(?=\\W|$)`); |
||
| 28 | } |
||
| 29 | } |
||
| 30 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.